package com.gcb.util;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	
	public static String date2String(Object date){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(date);
	}
	
	public static String getYearOldOracle(String pccard){
		String age = "";
		CallableStatement cs = null;
		ConnOracle co = new ConnOracle();
		String sql = "{? = call f_yearold(?)}";
		cs = co.getCstmt(sql);
		try {
			cs.registerOutParameter(1, Types.VARCHAR);
			cs.setString(2, pccard);
			cs.execute();
			age = cs.getString(1);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return age;
	}
	
	/**
	 * 根据身份证号码获取性别(返回值：1－男，2－女，空为身份证号码错误)
	 * 
	 * @param id
	 * @return
	 * @exception Exception
	 */
	public static String getGender(String iDCard) {
		int gender = 3;
		System.out.print(iDCard);
		if (iDCard.length() == 15) {
			gender = (new Integer(iDCard.substring(14, 15))).intValue() % 2;
		} else if (iDCard.length() == 18) {
			int number17 = (new Integer(iDCard.substring(16, 17))).intValue();
			gender = number17 % 2;
		}
		if (gender == 1) {
			return "1";
		} else if (gender == 0) {
			return "2";
		} else {
			return "";
		}
	}
}
